/**
 * 计算原价
 * @param project
 * @returns project
 */
export function computeOriginalPrice(project) {
  const { unitPrice, count } = project
  project.originalPrice = (+unitPrice * +count).toFixed(2)
  return project
}
/**
 * 计算折后价格
 * @param project
 * @returns project
 */
export function computeDiscountPrice(project) {
  const { originalPrice, discount } = project
  project.discountPrice = ((+originalPrice * +discount) / 100).toFixed(2)
  return project
}
/**
 * 计算折扣
 * @param project
 * @returns project
 */
export function computeDiscount(project) {
  const { originalPrice, discountPrice } = project
  project.discount = Math.min(
    Math.floor((+discountPrice / +originalPrice) * 100),
    100
  )
  return project
}
/**
 * 计算实收价格
 * @param project
 * @returns {default.methods}
 */
export function computePaidInPrice(project) {
  const { discountPrice, deductionAmount } = project
  project.paidInPrice = (+discountPrice - +deductionAmount).toFixed(2)
  return project
}
/**
 * 计算应收价格
 * @param project
 * @returns project
 */
export function computeReceivablePrice(project) {
  const { paidInPrice, petCardAmount } = project
  project.payAmount = project.receivablePrice = (
    +paidInPrice - +petCardAmount
  ).toFixed(2)
  return project
}
/**
 * 计算储值金划扣金额
 * @param project
 * @returns project
 */
export function computePetCardAmount(project) {
  const { discountPrice, deductionAmount, petCardAmount } = project
  project.petCardAmount = Math.min(
    +discountPrice - +deductionAmount,
    +petCardAmount
  ).toFixed(2)
  return project
}
/**
 * 计算折扣金额
 * @param project
 * @returns project
 */
export function computeDeductionAmount(project) {
  const { discountPrice, petCardAmount, deductionAmount } = project
  project.deductionAmount = Math.min(
    +discountPrice - +petCardAmount,
    +deductionAmount
  ).toFixed(2)
  return project
}

/**
 * 清除优惠 重置金额
 *
 * @param project
 * @returns {*}
 */
export function resetAmount(project) {
  project.petCardAmount = '0.00'
  project.deductionType = ''
  project.deductionAmount = '0.00'
  return project
}
